// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/order/api/WorkOrderApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/order/model/QueryWorkOrderListReq'
import BaseClass from '@api/order/model/WorkOrderDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'workOrderDto']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  validParam(param) {
    return !CORE.isEmpty(param.statusList)
  },
  transParam(param) {
    return { ...param, status: (param.statusList || []).join() }
  },
  async getList(param, TIP = '查询工单列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM, BASE)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryWorkOrderList', DTO)
    return [resp.comQuery.totalCount, resp.workOrderDto || [], resp.workOrderStatusCountDto || {}]
  },
  dealList([obj], { state: { MAP } }) {
    if (MAP.COUNT) MAP.COUNT = obj || {}
  },
}
